import React, { Component } from 'react';
import { Icon, Input, Button, Table, message } from 'antd';
import { withRouter } from 'react-router';
import axios from 'axios';
import './index.less';
const Search = Input.Search;
const columns = [
  {
    title: '序号',
    dataIndex: 'id',
    key: 'id',
  }, {
    title: '菜单',
    dataIndex: 'menu',
    key: 'menu',
  }, {
    title: '操作',
    dataIndex: 'opt',
    key: 'opt',
  }, {
    title: '资源路径',
    dataIndex: 'uri',
    key: 'uri',
  }, {
    title: '操作时间',
    dataIndex: 'crtTime',
    key: 'crtTime',
  }, {
    title: '操作人ID',
    dataIndex: 'crtUser',
    key: 'crtUser',
  }, {
    title: '操作人',
    dataIndex: 'crtName',
    key: 'crtName',
  }, {
    title: '操作主机',
    dataIndex: 'crtHost',
    key: 'crtHost',
  }
];


class Notes extends React.Component {
  constructor(props) {
    super(props);
    this.state = {};
  }
  getLogs = () => {
    const $this = this;
    const Token = sessionStorage.getItem('token');
    axios({
      method: 'get',
      url: '/api/admin/gateLog/all',
      headers: {
        Authorization: Token
      }
    })
    // axios.post('/api/auth/jwtcustomer/customertoken',values)
      .then(function (response) {
        $this.setState({
          data: response.data
        });
      })
      .catch(function (error) {
        message.error('请求失败，请稍后重试');
      });
  }
  // 条件搜索
  searchUser = (value) => {
    const $this = this;
    const Token = sessionStorage.getItem('token');
    axios({
      method: 'get',
      url: '/api/admin/gateLog',
      headers: {
        Authorization: Token
      },
      params: {
        name: value
      }
    }).then(function (response) {
      $this.setState({
        data: response.data
      });
      // console.log(response.data)
    }).catch(function (error) {
      message.error('请求失败，请稍后重试');
    });

  }
  componentWillMount() {
    this.getLogs();

  }
  render() {
    const { match, location, history } = this.props;
    return (
      <div>
        <div className="index-buttons">
          <Search placeholder="菜单或操作" onSearch={value => this.searchUser(value)} enterButton size="large" style={{ width: 260 }} />
        </div>
        <Table columns={columns} dataSource={this.state.data} rowKey="id" bordered />
      </div>


    );
  }
}

export default withRouter(Notes);
